package com.tang.utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author tang
 * @create 2020-08-17
 */

/**
 * 制造数据库数据
 */
public class DataCreate {
    public static void main(String[] args) {
        Connection connection = JDBCTools.getConnection();
        String sql = "INSERT INTO `book` (`id`, `name`, `author`, `publish`, `pages`, `price`, `bookcaseid`, `abled`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";

        PreparedStatement statement = null;


        for (int j = 3; j <50 ; j++) {
            try {
                statement = connection.prepareStatement(sql);
                statement.setInt(1,j);
                statement.setString(2,"书本"+j);
                statement.setString(3,"作者"+j);
                statement.setString(4,"出版社"+j);
                statement.setInt(5, 100+j*10);
                statement.setInt(6,20+j);
                statement.setInt(7, j%10);
                statement.setInt(8, j+1);
                boolean execute = statement.execute();
            } catch (SQLException e) {
                e.printStackTrace();
            }


        }
//        String sql = "INSERT INTO `bookcase` (`id`, `type`) VALUES (?, ?)";
//        PreparedStatement statement = null;
//        for (int i = 0; i < 10; i++) {
//            try {
//                statement = connection.prepareStatement(sql);
//                statement.setInt(1,i);
//                statement.setString(2,"类别"+i);
//                boolean execute = statement.execute();
//            } catch (SQLException e) {
//                e.printStackTrace();
//            }
//
//
//        }
        JDBCTools.release(connection,statement);

    }
}
